﻿using System;
using SilentWebsite.Model.Contracts;
using SilentWebsite.Web.Services;

namespace SilentWebsite.Model.Services
{
    public class ServicesUnitOfWork : IUnitOfWork<SilentContext>
    {
        private static readonly Lazy<ServicesUnitOfWork> lazy = new Lazy<ServicesUnitOfWork>();
        public static ServicesUnitOfWork Current
        {
            get { return lazy.Value; }
        }

        public SilentContext Entity { get; private set; }

        public ServicesUnitOfWork()
        {
            Entity = new SilentContext();
        }

        public bool Commit()
        {
            Entity.SubmitChanges();
            return true;
        }
        public void Rollback()
        {
            Entity.RejectChanges();
            Entity = new SilentContext();
        }
    }
}
